package life.exam02;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class LifeBeanImpl implements LifeBean, BeanNameAware, ApplicationContextAware {
	private String beanName;
	private ApplicationContext context;
	
	// This method is used when the bean object should know it's own name.
	// This will be injected the object id value when it is created.
	public void setBeanName(String beanName) {
		System.out.println("setBeanName(...) Execution...");
		this.beanName = beanName;
	}
	
	// The method which Spring's ApplicationContext is handed to when the object is created.
	// This is used when ApplicationContext is handed to the bean.
	public void setApplicationContext(ApplicationContext context) throws BeansException {
		System.out.println("setApplicationContext(...) Execution...");
		this.context = context;
	}
	
	public void lifeMessage() {
		System.out.println("life Business logic execution is in progress...");
		OtherBean other = (OtherBean) context.getBean("otherBean");
		other.otherMessage();
	}
}
